import { IDevice, DeviceInfo, HostInfo } from "../IDevice";

export class TTDevice extends IDevice{
    protected _tt:any;
    protected _systemInfo:any;
    init(type: string): IDevice {
        this._tt = window['tt'];
        return super.init(type);
    }
    
    vibrate(long: boolean): void {
        if(!this.vibrateAble){
            return;
        }
        long ? this._tt.vibrateLong({}) : this._tt.vibrateShort({});
    }

    get deviceInfo():DeviceInfo {
        if (!this._systemInfo) {
            this._systemInfo = this._tt.getSystemInfoSync();
        }
        return {
            brand: this._systemInfo.brand,
            system: this._systemInfo.system,
            model: this._systemInfo.model,
            platform: this._systemInfo.platform
        }
    }

    get hostInfo():HostInfo {
        if (!this._systemInfo) {
            this._systemInfo = this._tt.getSystemInfoSync();
        }
        return {
            name: this._systemInfo.appName,
            version: this._systemInfo.version
        }
    }
}
